// pages/asc/myMessage/myMessage.js
var _http = require('../../../utils/httpUtils.js');
var _utils = require('../../../utils/utils.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list_row:10, //每页个体数
        page:1,  //页码
        messList: [{
            "time": "2-26",
            "content": "就测试到这里吧"
        }, {
            "time": "2-25",
            "content": "这是一条消息呢"
        }, {
            "time": "2-25",
            "content": "这是一条消息呢"
        }, {
            "time": "2-25",
            "content": "这是一条消息呢"
        }, {
            "time": "2-25",
            "content": "这是一条消息呢"
        }, {
            "time": "2-23",
            "content": "这是一条消息呢"
        }, {
            "time": "2-21",
            "content": "注册成功!"
        }, {
            "time": "2-21",
            "content": "Your registration was successful, student ID:1234561234 password: 1234565"
        }]

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

        //加载list
        getList(this);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.setData({
            page:this.data.page+1
        })

        getList(this);
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})
function getList(_this){
    if(_this.data.page == 1){
        _this.setData({
            mList:[]
        })
    }
    _http.post(_http.myMessage,{"page":_this.data.page,"list_row":_this.data.list_row},function(res){
        var list = res.data.list;
        if(list){
            for (let i = 0; i < list.length; i++) {
                const el = list[i];
                var to = el.create_time;
                to = _utils.formatDate(to,'MM-DD')
                list[i].create_time = to;
            }
        }
        _this.setData({
            mList:list.concat(_this.data.mList)
        })
    })
}